var iNum1;
var iNum2;
var items = ['体育竞赛','文艺比赛','篮球赛','足球赛','队伍','宿舍','宿舍美化大赛'];
var levels =[["国一","国二","国三","国参","省一","省二","省三","省参","市一","市二","市三","市参","校一","校二","校三","校参","院一","院二","院三","院参","系一","系二","系三","系参"],
    ["国一","国二","国三","国参","省一","省二","省三","省参","市一","市二","市三","市参","校一","校二","校三","校参","院一","院二","院三","院优","院参", "系一","系二","系三","系优","系参"],
    ["院级","系级"],
    ["院级","系级"],
    ['文艺','体育','辩论队'],
    ['十佳文明','文明','系星级'],
    ["院一","院二","院三","院优","系一","系二","系三","系优"]

];
var points =[
        [[30],[20],[15],[7.5],  [20],[15],[12],[6],  [15],[12],[10],[5]  [12],[10],[8],[4]  [10],[8],[6],[3]  [6],[4],[3],[1.5]],
        [[30],[20],[15],[7.5],  [20],[15],[12],[6]  [15],[12],[10],[5]  [12],[10],[8],[4]  [10],[8],[6],[4],[2]  [6],[4],[3],[2],[1]],
        [[3],[2]],
        [[3],[2]],
        [[4],[4],[4]],
        [[10],[6],[3]],
        [[10],[8],[6],[4],[6],[4],[3],[2]]
    ];
$(document).ready(
    initdate()
);
function initdate(){

    $(function (){
        // // 1.页面加载初始化就已经填入默认值
        // for(var i=0;i<items.length;i++){
        //     $('.selItems').append('<option>'+items[i]+'</option>');
        // }
        // iNum1 = $(".selItems option:selected").index();
        // var default_uni = levels[iNum1];
        // for(var s=0;s<default_uni.length;s++){
        //     $('.selLevels').append('<option>'+default_uni[s]+'</option>');
        // }
        // iNum2 = $(".selLevels option:selected").index();
        // var default_mem = points[iNum1][iNum2];
        // for(var g=0;g<default_mem.length;g++){
        //     $('.selPoints').append('<option>'+default_mem[g]+'</option>');
        // }

        // 两个两个之间的绑定事件
        $(document).delegate('.selItems',"change",function () {

            $(this).parent('.form-group').children('.selLevels').children().remove();
            $(this).parent('.form-group').children('.selLevels').children('.selPoints').children().remove();
            iNum1 = $(this).children('option:selected').index();
            var alevels = levels[iNum1];
            for(var j=0;j<alevels.length;j++){
                $(this).parent('.mb-3').children('.selLevels').append('<option>'+alevels[j]+'</option>');
            }
            // $(this).next('select.selLevels').trigger("change");//三个联动的关键代码
            $(this).next().next('select.selLevels').trigger("change");//三个联动的关键代码
        });

        $(document).delegate('.selLevels',"change",function () {
            // $(this).next('select.selPoints').children().remove();
            $(this).next().next('select.selPoints').children().remove();
            iNum2 = $(this).children('option:selected').index();
            var apoints = points[iNum1][iNum2];
            for(var k=0;k<apoints.length;k++){
                // $(this).next('select.selPoints').append('<option>'+apoints[k]+'</option>');
                $(this).next().next('select.selPoints').append('<option>'+apoints[k]+'</option>');

            }
            addpoint();

        })
    })
}
function addpoint() {
    var countPoint=0;
    // if (itemID.id=="2"){
    //     // countPoint=2;
    // }
    $("select.selPoints").each(function (it) {

        countPoint=countPoint+Number($(this).children().text());
        // alert(countPoint)
    })

    $("#subtotal").val(countPoint);
    $("#score").val((countPoint*0.15).toFixed(2));
}
function add_bind_op(){
    // var iNum1;
    // var iNum2;
    // var items= ['高校计算机等级考试','全国计算机等级考试','软考(专业技能考试)','英语','驾驶证','初级会计证','教师资格证','红十字救护证'];
    // var levels =[["一级","二级","三级","四级"],["一级","二级","三级","四级"],["初级","中级","高级"],['四级','六级'],[""],[""],[""],[""]
    // ];
    // var points=[[[2],[4],[6],[8]],[[3],[5],[10],[15]],[[10],[15],[20]],[[10],[15]],[[5]],[[5]],[[10]],[[3]]];
    $(function(){
        // 1.页面加载初始化就已经填入默认值
        for(var i=0;i<items.length;i++){
            $('.selItems').last().append('<option>'+items[i]+'</option>');
        }
        iNum1 = $(".selItems option:selected").index();
        var default_uni = levels[iNum1];
        for(var s=0;s<default_uni.length;s++){
            $('.selLevels').last().append('<option>'+default_uni[s]+'</option>');
        }
        iNum2 = $(".selLevels option:selected").index();
        var default_mem = points[iNum1][iNum2];
        for(var g=0;g<default_mem.length;g++){
            $('.selPoints').last().append('<option>'+default_mem[g]+'</option>');
        }
        // 两个两个之间的绑定事件
    })

}